﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using MathematicallySafe.HeadCounter.Common;
using MathematicallySafe.HeadCounter.ViewModels;

namespace MathematicallySafe.HeadCounter.Views
{
    /// <summary>
    /// Interaction logic for RaiderHistoryView.xaml
    /// </summary>
    public partial class RaiderHistoryView : UserControl
    {
        public RaiderHistoryView()
        {
            InitializeComponent();
        }

        public RaiderDetailedViewModel ViewModel
        {
            get { return DataContext as RaiderDetailedViewModel; }
        }

        private void HyperlinkOnRequestNavigate(object sender, RequestNavigateEventArgs e)
        {
            Utilities.HyperlinkRequestNavigate(sender, e);
        }
    }

    #region local converters

    public class HistoryAttendanceBackgroundConverter : IValueConverter
    {
        public bool IsBackground { get; set; }

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return IsBackground
                           ? System.Windows.Application.Current.Resources["DefaultBackground"]
                           : System.Windows.Application.Current.Resources["DefaultForeground"];

            var historyLine = (RaiderRaidHistoryLine) value;

            if (historyLine.Attended)
            {
                if (historyLine.Optional)
                {
                    return IsBackground
                               ? System.Windows.Application.Current.Resources["AttendedOptionalBackground"]
                               : System.Windows.Application.Current.Resources["AttendedOptionalForeground"];
                }

                return IsBackground
                           ? System.Windows.Application.Current.Resources["AttendedBackground"]
                           : System.Windows.Application.Current.Resources["AttendedForeground"];
            }
            else
            {
                if (historyLine.Optional)
                {
                    return IsBackground
                               ? System.Windows.Application.Current.Resources["MissedOptionalBackground"]
                               : System.Windows.Application.Current.Resources["MissedOptionalForeground"];
                }

                return IsBackground
                           ? System.Windows.Application.Current.Resources["MissedBackground"]
                           : System.Windows.Application.Current.Resources["MissedForeground"];
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }

        #endregion
    }

    #endregion
}
